package com.javaee.my.dao;

import com.javaee.interceptor.entity.Shopping_Cart;
import com.javaee.interceptor.entity.goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface businessMapper {
    //向用户的购物车中添加数据
    @Insert("insert into shopping_cart (id,goods_id,nums,allprice) " +
            "values(#{id},#{goods_id},#{nums},#{allprice})")
    @Options(useGeneratedKeys=true, keyProperty="shopping_cart_id", keyColumn="shopping_cart_id")
    int addGoodsToShopping_cart(Shopping_Cart shopping_cart);
    //核实商品信息
    @Select("select * from goods where goods_id=#{goods_id}")
    goods check_goods(@Param("goods_id")Integer goods_id);
    //修改商品数量
    @Update("update goods set goods_nums=#{goods_nums} where goods_id=#{goods_id}")
    int update_goodsNums(@Param("goods_nums") goods resgoods);
    //根据商品的id删除购物车中的商品
    @Delete("delete from shopping_cart where goods_id=#{goods_id} and id=#{id}")
    int deleteGoods(Shopping_Cart shopping_cart);
    //根据商品id查询购物车中的商品
    @Select("select * from shopping_cart where goods_id=#{goods_id} and id=#{id}")
    Shopping_Cart check_goodsInShopping_cart(Shopping_Cart shopping_cart);
    //更新购物车中的商品
    @Update("update shopping_cart set nums=#{nums},allprice=#{allprice} where goods_id=#{goods_id} and id=#{id}")
    int update_goodsInShopping_cart(Shopping_Cart shopping_cart);
    //查询用户购物车中的所有商品
    @Select("select * from shopping_cart where id=#{id}")
    List<Shopping_Cart> select_Shopping_cartBy_id(@Param("id")Integer id);
    //查询用户购物车中的最终总价格
    @Select("select sum(allprice) from shopping_cart where id=#{id}")
    float select_Shopping_cart_allprice(@Param("id")Integer id);

}
